<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	/**
	 * CodeIgniter
	 *
	 * An open source application development framework for PHP 4.3.2 or newer
	 *
	 * @package		CodeIgniter
	 * @author		ExpressionEngine Dev Team
	 * @copyright	Copyright (c) 2008 - 2009, EllisLab, Inc.
	 * @license		http://codeigniter.com/user_guide/license.html
	 * @link		http://codeigniter.com
	 * @since		Version 1.0
	 * @filesource
	 */
	// ------------------------------------------------------------------------
	
	/**
	 * @package		CodeIgniter
	 * @subpackage	Libraries
	 * @author		AnhDT
	 */
	require_once APP_LIBRARY_PATH . 'tree/paginator/engine/st_paginator_engine_interface.php';
	class st_paginator_collection implements st_paginator_engine_interface {
		protected $_model = null;
		protected $_count = null;
		public function __construct(st_model $_model = null) {
			$this->setModel($_model);
		}	
		/** Đếm số lượng bản ghi có trong bộ phân trang */
		public function count() {
			if (empty($this->_model)) {
				return 0;	
			}
			return $this->_model->countTotal();
		}
		/**Lấy về các bản ghi thuộc 1 trang*/
		public function getItems($_offset, $_itemCountPerPage) {
			if (empty($this->_model)) {
				return false;	
			}
			return $this->_model->setLimit($_offset, $_itemCountPerPage)
						        ->getCollection();
		}
		/**Thiết lập model cho bộ phân trang*/
		public function setModel($_model = null) {
			if ($_model === null && !$_model instanceof st_model) {
				return false;	
			}
			$this->_model = & $_model;
			return $this;
		}
		/**Lấy về model cho bộ phân trang*/
		public function getModel() {
			return $this->_model;	
		}
	}
?>